package com.cjg.array;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

public class callableDemo {
    public static void main(String[] args) throws Exception {
        //Thread(Runnable)
        //Thread(new FutureTask<V>())FutureTask是Runnable实现类
        // /Thread(new FutureTask<V>(Callable))//FutureTask可以放入Callable和Runnale
        MyThread myThread = new MyThread();
        //缓冲区
        FutureTask<Integer> integerFutureTask = new FutureTask<>(myThread);
        new Thread(integerFutureTask).start();
        new Thread(integerFutureTask).start(); // 结果会被缓存
        //获取Callable的返回值 可能会产生阻塞
        //放在最后或者        异步通讯
        Integer integer = integerFutureTask.get();
        System.out.println(integer);

    }
}
class MyThread implements Callable<Integer>{

    @Override
    public Integer call() throws Exception {
        System.out.println("1024");
        return 0;
    }
}
